<?php
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require 'dbcon.php';
require 'isok.php';
$title=$_REQUEST['title'];
$content=$_REQUEST['content'];
$slug=$_REQUEST['slug'];
$filename= time();
$name=$_FILES['feature']['name'];
$pathinfo= pathinfo($name);
$ext=$pathinfo['extension'];
$path='images/feature/'. $filename . '.'. $ext;
move_uploaded_file($_FILES['feature']['tmp_name'], $path);
$feature=$path;
$created=$_REQUEST['created'];
$category_id=$_REQUEST['category_id'];
$status=$_REQUEST['status'];
$user_id=$userinfo['id'];
$sql="insert into posts(title,content,slug,feature,created,category_id,status,user_id) values('{$title}','{$content}','{$slug}','{$feature}','{$created}','{$category_id}','{$status}','{$user_id}')";
$rs=$db->query($sql);//$rs 返回值  如果成功，返回true 如果失败，返回false
$db->close();//关闭数据库连接
if ($rs==true)
{
    header("Location:isposts.php");
}
 else {
   echo '<script type="text/javascript">'; 
   echo 'alert("添加失败");';
   echo 'window.location.href="ispost-add.php";';
   echo '</script>';
}